<?php
// import enums
require_once ("../enums/enums.php");

// import DO
require_once ("../persistance/data/ResponsableDO.php");
require_once ("../persistance/data/ClientDO.php");
require_once ("../persistance/data/ArticleDO.php");
require_once ("../persistance/data/PromotionDO.php");
require_once ("../persistance/data/TypeArticleDO.php");
require_once ("../persistance/data/HistoriqueDO.php");

// import DAO
require_once ("../persistance/dao/ResponsableDAO.php");
require_once ("../persistance/dao/ClientDAO.php");
require_once ("../persistance/dao/ArticleDAO.php");
require_once ("../persistance/dao/PromotionDAO.php");

// import Bean data
require_once ("../bean/data/Utilisateur.php");
require_once ("../bean/data/Article.php");
require_once ("../bean/data/Promotion.php");
require_once ("../bean/data/Client.php");
require_once ("../bean/data/TypeArticle.php");
require_once ("../bean/data/Historique.php");
class ResponsableService {
	private $responsableDAO;
	private $articleDAO;
	private $promotionDAO;
	private $clientDAO;
	public function __construct() {
		$this->responsableDAO = new ResponsableDAO ();
		$this->articleDAO = new ArticleDAO ();
		$this->promotionDAO = new PromotionDAO ();
		$this->clientDAO = new ClientDAO ();
	}
	
	// -----------------------SERVICES-----------------------------------------------------------------------
	/**
	 * Retourne tout les articles present dans la base
	 */
	public function getListArticle() {
		$listArticleDO = $this->articleDAO->getListArticleDO ();
		$listArticle = new ArrayObject ();
		foreach ( $listArticleDO as $articleDO ) {
			$article = $this->convertArticleDOtoArticle ( $articleDO );
			$listArticle->append ( $article );
		}
		return $listArticle;
	}
	
	/**
	 * Retourne tout les articles present dans la base
	 */
	public function getHistorique() {
		$listPromoClientDO = $this->promotionDAO->getHistorique ();
		$listPromoClient = new ArrayObject ();
		foreach ( $listPromoClientDO as $historiqueDO ) {
			$historique = $this->convertHistoriqueDOtoHistorique ( $historiqueDO );
			$listPromoClient->append ( $historique );
		}
		return $listPromoClient;
	}
	public function getPromoNonLuClient($numClient) {
		$listPromoClientDO = $this->promotionDAO->getPromoNonLuClient ( $numClient );
		$listPromoClient = new ArrayObject ();
		foreach ( $listPromoClientDO as $historiqueDO ) {
			$historique = $this->convertHistoriqueDOtoHistorique ( $historiqueDO );
			$listPromoClient->append ( $historique );
		}
		return $listPromoClient;
	}
	
	/**
	 * Retourne le client par rapport a son login
	 */
	public function getClient($login_client) {
		$clientDO = $this->clientDAO->getClientDO ( $login_client );
		$client = new ArrayObject ();
		$client = $this->convertClientDOtoClient ( $clientDO );
		return $client;
	}
	/**
	 * Retourne tout les articles present dans la base
	 */
	public function getListPromoArticleDuMoment() {
		$listArticlePromoDO = $this->promotionDAO->getListPromoDuMomentDO ();
		$listArticlePromo = new ArrayObject ();
		foreach ( $listArticlePromoDO as $promotionDO ) {
			$promotion = $this->convertPromotionDOtoPromotion ( $promotionDO );
			$listArticlePromo->append ( $promotion );
		}
		return $listArticlePromo;
	}
	
	/**
	 * Retourne toutes les promos presentent dans la base
	 */
	public function getListPromoDuMoment() {
		$listPromoDuMomentDO = $this->promotionDAO->getListArticlePromoDuMomentDO ();
		
		$listPromoDuMoment = new ArrayObject ();
		foreach ( $listPromoDuMomentDO as $promotionDO ) {
			$promotion = $this->convertPromotionMomentDOtoPromotionMoment ( $promotionDO );
			$listPromoDuMoment->append ( $promotion );
		}
		return $listPromoDuMoment;
	}
	/**
	 * Retourne un article
	 */
	public function getArticle($numArticle) {
		$articleDO = $this->articleDAO->getArticleDO ( $numArticle );
		$article = new ArrayObject ();
		$article = $this->convertArticleDOtoArticle ( $articleDO );
		
		return $article;
	}
	
	/**
	 * Retourne un article
	 */
	public function getArticleByName($nomArticle) {
		$articleDO = $this->articleDAO->getArticleByNameDO ( $nomArticle );
		$article = new ArrayObject ();
		$article = $this->convertArticleDOtoArticle ( $articleDO );
		
		return $article;
	}
	
	/**
	 * Retourne un article
	 */
	public function getArticlePromo($numPromo) {
		$articleDO = $this->articleDAO->getArticlePromoDO ( $numPromo );
		$article = new ArrayObject ();
		$article = $this->convertArticleDOtoArticle ( $articleDO );
		
		return $article;
	}
	
	/**
	 * Retourne une promo
	 */
	public function getPromo($numPromo) {
		$promotionDO = $this->promotionDAO->getPromoDO ( $numPromo );
		$promotion = new ArrayObject ();
		$promotion = $this->convertPromotionMomentDOtoPromotionMoment ( $promotionDO );
		
		return $promotion;
	}
	
	/**
	 * Retourne toutes les promos presentent dans la base
	 */
	public function getListPromo($typeArticle) {
		$listPromoDO = $this->promotionDAO->getListPromoDO ( $typeArticle );
		$listPromo = new ArrayObject ();
		
		foreach ( $listPromoDO as $promotionDO ) {
			$promotion = $this->convertPromotionDOtoPromotion ( $promotionDO );
			$listPromo->append ( $promotion );
		}
		return $listPromo;
	}
	
	/**
	 * Retourne toutes les promos presentent dans la base
	 */
	public function getListArticlePromoDuMoment() {
		$listPromoDuMomentDO = $this->promotionDAO->getListArticlePromoDuMomentDO ();
		
		$listPromoDuMoment = new ArrayObject ();
		foreach ( $listPromoDuMomentDO as $promotionDO ) {
			$promotion = $this->convertPromotionMomentDOtoPromotionMoment ( $promotionDO );
			$listPromoDuMoment->append ( $promotion );
		}
		return $listPromoDuMoment;
	}
	
	/**
	 * Retourne tous les clients presentent dans la base
	 */
	public function getListClient() {
		$listClientDO = $this->clientDAO->getListClientDO ();
		$listClient = new ArrayObject ();
		foreach ( $listClientDO as $clientDO ) {
			$client = $this->convertClientDOtoClient ( $clientDO );
			$listClient->append ( $client );
		}
		return $listClient;
	}
	
	/**
	 * Retourne tous les clients presentent dans la base
	 */
	public function getListTypeArticle() {
		$listTypeArticleDO = $this->articleDAO->getListTypeArticleDO ();
		$listTypeArticle = new ArrayObject ();
		foreach ( $listTypeArticleDO as $typeArticleDO ) {
			$typeArticle = $this->convertTypeArticleDOtoTypeArticle ( $typeArticleDO );
			$listTypeArticle->append ( $typeArticle );
		}
		return $listTypeArticle;
	}
	
	// -----------------------CONVERTION-----------------------------------------------------------------------
	private function convertArticleDOtoArticle(ArticleDO $articleDO) {
		$article = new Article ();
		$article->setLibelle ( $articleDO->getLibelle () );
		$article->setNumArticle ( $articleDO->getNumArticle () );
		$article->setLibelleTypeArticle ( $articleDO->getLibelleTypeArticle () );
		$article->setPrixUnitaire ( $articleDO->getPrixUnitaire () );
		$article->setQuantite ( $articleDO->getQuantite () );
		
		return $article;
	}
	private function convertPromotionDOtoPromotion(PromotionDO $promotionDO) {
		$promotion = new Promotion ();
		$promotion->setNumPromo ( $promotionDO->getNumPromo () );
		$promotion->setLibelle ( $promotionDO->getLibelle () );
		$promotion->setPourcentagePromo ( $promotionDO->getPourcentagePromo () );
		$promotion->setPromoDuMoment ( $promotionDO->getPromoDuMoment () );
		$promotion->setNumArticle ( $promotionDO->getNumArticle () );
		
		return $promotion;
	}
	private function convertPromotionMomentDOtoPromotionMoment(PromotionDO $promotionDO) {
		$promotion = new Promotion ();
		$promotion->setNumPromo ( $promotionDO->getNumPromo () );
		$promotion->setLibelle ( $promotionDO->getLibelle () );
		$promotion->setPourcentagePromo ( $promotionDO->getPourcentagePromo () );
		$promotion->setPromoDuMoment ( $promotionDO->getPromoDuMoment () );
		$promotion->setLibelleArt ( $promotionDO->getLibelleArt () );
		$promotion->setNumArticle ( $promotionDO->getNumArticle () );
		$promotion->setLibelleTypeArticle ( $promotionDO->getLibelleTypeArticle () );
		$promotion->setPrixUnitaire ( $promotionDO->getPrixUnitaire () );
		
		return $promotion;
	}
	private function convertHistoriqueDOtoHistorique(HistoriqueDO $historiqueDO) {
		$historique = new Historique ();
		$historique->setNumPromo ( $historiqueDO->getNumPromo () );
		$historique->setNomClient ( $historiqueDO->getnomClient () );
		$historique->setLibelle ( $historiqueDO->getLibelle () );
		return $historique;
	}
	private function convertClientDOtoClient(ClientDO $clientDO) {
		$client = new Client ();
		$client->setNumClient ( $clientDO->getnumClient () );
		$client->setLoginClient ( $clientDO->getLoginClient () );
		$client->setNomClient ( $clientDO->getNomClient () );
		$client->setPrenomClient ( $clientDO->getPrenomClient () );
		$client->setEmailClient ( $clientDO->getEmailClient () );
		$client->setTelClient ( $clientDO->getTelClient () );
		$client->setTypeClient ( $clientDO->getTypeClient () );
		$client->setDateInscription ( $clientDO->getDateInscription () );
		$client->setNbVisites ( $clientDO->getNbVisites () );
		$client->setConnecte ( $clientDO->getConnecte () );
		
		return $client;
	}
	private function convertTypeArticleDOtoTypeArticle(TypeArticleDO $typeArticleDO) {
		$TypeArticle = new TypeArticle ();
		$typeArticleDO->setLibelleTypeArticle ( $typeArticleDO->getLibelleTypeArticle () );
		
		return $typeArticleDO;
	}
}
